<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>拖车渠道银行账号</title>
<jsp:include page="../../import.jsp" flush="true" />
<%--<jsp:include page="assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->--%>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <div class="btnsBox inLC">
                    <span id="addAcc" class="sq-button sq-button-round">新增</span>
                </div>
                <span>拖车渠道银行账号</span>
            </div>
        </div>
        <!-- 列表显示块 -->
        <div id="ligergrid_bankacc" class="sq-grid"></div>
        <input name="chnId" id="chnId" type="hidden" value="${chnId}">
    </div>
</div>

<script type="text/javascript">
    var grid = null;
    $(function () {
        initEvent();
        initGrid();
    });

    //初始化事件
    function initEvent(){
        //新增账号事件
        $("#addAcc").click(function(event) {
            //如果渠道ID不存在是不能新增的
            var chnId = $("#chnId").val();
            if(!chnId){
                UIUtils.alertWarning("请确定拖车渠道信息存在后在操作！");
                return; //验证不通过，不执行以下代码
            }
            var id = "";
            addAcc(id);
        });
    }

    //存在一个启用状态的 取消掉新增按钮
  function displayInsert() {
        $("#addAcc").css("display","none");
        // $("#addAcc").attr('disabled','disabled');
    }

    //初始化列表
	function initGrid(){
	    //查询该拖车渠道下的账号
        var chnId = $("#chnId").val();
		$("#ligergrid_bankacc").ligerGrid({
			url:'<%=path%>/ass/assChnBankAcc/initList.do?channelId='+chnId,
			method:'get',
			//parms:getSearchParams(),
			columns:[
                { display: '账户名', name: 'accNm', width: 100, enabledSort:true},
				{ display: '开户银行', name: 'bkNm', width: 120, enabledSort:true,},
				{ display: '分行支行', name: 'accOrgNm', width: 170, enabledSort:true,},
                { display: '开户行行号', name: 'bkNo', width: 150, enabledSort:true,},

                { display: '银行账号', name: 'accNo', width: 150, enabledSort:true},
                { display: '账户类型', name: 'accTypCdNm', width: 100, enabledSort:true},
				{ display: '是否启用', name: 'isValid', width: 100, enabledSort:true,
                    render:function (rowdata, rowindex, value){
                        //存在一个启用的的 新增不可用
                        if (value == "1") {
                            displayInsert();
                        }
                        return (value == "1")?"启用中":"禁用";
                    }
                },
				getGridOperColumnContent()//操作列
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			checkbox:true,//列表是否有选择框
			rownumbers:true//列表是否有行号
		});
		grid = liger.get("ligergrid_bankacc");
		grid.setHeight(100);
		grid.options.isSingleCheck = false;//列表是否为单选
	}

	//操作列
    function getGridOperColumnContent(){
		var data = {
			display:'操作',
			isSort:false,
			width:150,
            align:'left',
			render:function (rowdata, rowindex, value){
				var h="";
            	h+='<a class="sq-button-hasicon" alt="修改" href="javascript:addAcc(';
                h+="'"+rowdata.id+"'";
                h+=")\"><i class=\"sqBtnIco_4\"></i>"+LogUtils.LOG_CMM_GRID_BTN_MODIFY+"</a>";

                var v;
                var v1='<a class="sq-button-hasicon" href="javascript:;" onclick="enable(';
                v1+="'"+rowdata.id+"'";
                v1+=",'"+rowdata.isValid+"'";
                v1+=')"><i class="sqBtnIco_13"></i>'+LogUtils.LOG_CMM_GRID_BTN_DISABLE+'</a>';

                var v2;
                // if (displayFlag) {
                //     v2='<a class="sq-button-hasicon" href="javascript:;" onclick="enable(';
                // } else {
                //     v2='<a class="sq-button-hasicon" style="display: none" href="javascript:;" onclick="enable(';
                // }
                v2='<a class="sq-button-hasicon"  href="javascript:;" onclick="enable(';
                v2+="'"+rowdata.id+"'";
                v2+=",'"+rowdata.isValid+"'";
                v2+=')"><i class="sqBtnIco_12"></i>'+LogUtils.LOG_CMM_GRID_BTN_ENABLE+'</a>';
                switch (rowdata.isValid){
                    case 0:
                        v=v2;
                        break;
                    case 1:
                        v=v1;
                        break;
                    default:
                        v=v1;
                        break;
                }
				return h + v;
			}
		};
		return data;
	}

    //新增/修改渠道账户
    function addAcc(id){
        var chnId = $("#chnId").val();
        $.ligerDialog.SQopen({
            width: 800,
            height:210,
            title : '拖车渠道银行账户',
            url:'<%=path%>/ass/assChnBankAcc/toAddPage.do?chnId='+chnId+'&bid='+id,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    //在子页面里绑定
                    // frameElement.dialog.onOk = function () {}
                    if (Dialog.onOk) Dialog.onOk();
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ]
        });
    }

    //启用 禁用
    function enable(id, isValid){
        if(!id)return;
        if (isValid == "1") {
            isValid = "0";
        } else {
            isValid = "1";
        }
        $.ligerDialog.confirm(LogUtils.LOG_CMM_ENABLE_CONFIRM, function (flag) {
            if(flag == false)return;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:{id:id, isValid:isValid},
                url: '<%=path%>/ass/assChnBankAcc/enable.do',
                success:function(msg){
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        // grid.reload();
                        // parent.pageInTab.selectTabItem('bankAcc');
                        parent.pageInTab.reload('bankAcc');
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

</script>
</body>
</html>